package com.llcbenwu.social.qq.connect;

import com.llcbenwu.social.qq.api.QQ;
import com.llcbenwu.social.qq.api.QQImpl;
import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;

/**
 * @author lilinchun
 * @date 2021/11/1 0001 20:22
 */
public class QQServiceProvider extends AbstractOAuth2ServiceProvider<QQ> {


    private  String appId;

    //Step1：获取Authorization Code 对应流程中的第一步将用户导向认证服务器
    private  static  final String URL_AUTHORIZE ="https://graph.qq.com/oauth2.0/authorize";

    //Step2：通过Authorization Code获取Access Token 对应流程中的第四步申请令牌
    private  static  final String URL_ACCESS_TOKEN ="https://graph.qq.com/oauth2.0/token";

    /**
     * OAuth2Template
     * @param appId
     * @param appSecret
     */
    public QQServiceProvider(String appId,String appSecret) {
        //clientId :appId
        //clientSecret :appSecret
        //authorizeUrl：将用户导向认证服务器
        //authenticateUrl ：申请令牌的url
//        super(new OAuth2Template( appId,  appSecret,  URL_AUTHORIZE, URL_ACCESS_TOKEN ));
        super(new QQOAuth2Template( appId,  appSecret,  URL_AUTHORIZE, URL_ACCESS_TOKEN ));
        this.appId=appId;
    }

    /**
     *  APi
     * @param accessToken
     * @return
     */
    @Override
    public QQ getApi(String accessToken) {
        return new QQImpl(accessToken,appId);
    }
}
